package com.atguigu.crowd.service.impl;

import com.atguigu.crowd.entity.Menu;
import com.atguigu.crowd.entity.MenuExample;
import com.atguigu.crowd.mapper.MenuMapper;
import com.atguigu.crowd.service.api.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author zzqstart
 * @Description
 * @date 2022-09-05 12:41
 */
@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuMapper menuMapper;

    @Override
    public List<Menu> getAll() {
        List<Menu> menuList = menuMapper.selectByExample(new MenuExample());
        return menuList;
    }

    @Override
    public void add(Menu menu) {
        menuMapper.insertSelective(menu);
    }

    @Override
    public void edit(Menu menu) {
        menuMapper.updateByPrimaryKeySelective(menu);
    }

    @Override
    public void remove(Integer id) {
        menuMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void assginAuthToMeun(Map<String,List<Integer>> map) {
        if (map == null || map.size()==0){
            return;
        }
        List<Integer> menuIdList = map.get("menuId");
        Integer menuId = menuIdList.get(0);

        menuMapper.deleteInnerDataBymenuId(menuId);

        List<Integer> authIdArray = map.get("AuthIdArray");

        if (authIdArray == null || authIdArray.size() == 0){
            return;
        }

        menuMapper.insertInnerData(menuId,authIdArray);
    }

    @Override
    public List<Integer> queryInnerMenuAuth(Integer menuId) {
        List<Integer> authIdList = menuMapper.selectInnerDataByMenuId(menuId);
        return authIdList;
    }
}
